//
//  ChaosResponse.m
//  Connection
//
//  Created by Worker on 3/17/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ChaosResponse.h"
#import "CJSONDeserializer.h"

@implementation ChaosResponse
@synthesize delegate = delegate_;
@synthesize httpStatusCode = httpStatusCode_;
@synthesize error = error_;
@synthesize responseData = responseData_;
@synthesize requestIdentifier = requestIdentifier_;
- (void)dealloc
{
	delegate_ = nil;
	[error_ release];
	error_ = nil;
	[responseData_ release];
	responseData_ = nil;
	[requestIdentifier_ release];
	requestIdentifier_ = nil;
	[super dealloc];
}

- (NSString *)description
{
	return [NSString stringWithFormat:@"ChaosResponse, statusCode=%d, error=%@,requestIdentifier=%@", 
			self.httpStatusCode, self.error,self.requestIdentifier];
}

- (void)setResponseData:(NSData *)data
{
	[responseData_ release];
	responseData_ = [data retain];
	NSError *theError = nil;
	NSDictionary *jsonDict = [[CJSONDeserializer deserializer] deserialize:responseData_ error:&theError];
	if (theError)
	{
		self.error = theError;
	}
	else {
		[jsonDictionary_ release];
		jsonDictionary_ = [[NSDictionary alloc] initWithDictionary:jsonDict];
	}
}

- (NSDictionary *)jsonDictionary
{
	return jsonDictionary_;
}

@end
